const oProgram = require('commander');
const oScan = require("./index.js");

oProgram
  .usage('[options] <file|dir|glob>*')

  .option('--ext <string>', '.js,.jsx,.vue,.css,.scss,.sass,.stylus,.less')
  .option('--jscpd-exts <string>', 'javascript:vue')
  .option('--ignore-path <path>', '.gitignore,.eslintignore')
  .option('--ignore-pattern <pattern>', 'vendor/**/*.js,static/**/*.js,dist/**,build/**,assets/**')
  .option('--filter-pattern <pattern>', 'Output percentage of all files but only details that related to the filter pattern')

  .option('--jscpd-min-lines <number>', 'min size of duplication, default to 5')
  .option('--jscpd-min-tokens <number>', 'default to 70')
  .option('--jscpd-max-lines <number>', 'max size of duplication, default to 3000')
  .option('--jscpd-max-size <number>', 'default to 200kb')
  .option('--threshold-jscpd <number>', 'default to null')
  .option('--output <string>', 'default to null')
  .option('--format <string>', 'default to html')
  .parse(process.argv);

const {
  args: aArgs = ['src'],
  ext: sExt = '.js,.jsx,.vue,.css,.scss,.sass,.stylus,.less,.tsx,.ts',
  jscpdExts: sJscpdExts = ['javascript', 'typescript', 'css', 'json', 'jsx', 'tsx', 'pug', 'sass', 'scss', 'less', 'stylus', 'styl'],
  jscpdMinLines: iJscpdMinLines = 5,
  jspcdMinTokens: iJscpdMinTokens = 70,
  jspcdMaxLines: iJspcdMaxLines = 300,
  jspcdMaxSize: iJspcdMaxSize = '200kb',
  thresholdJscpd: iThresholdJscpd = null,

  ignorePath: sIgnorePath = '.gitignore,.eslintignore',
  ignorePattern: sIgnorePattern = '**/src/public/**,**/node_modules/**,**/dist/**,**/build/**,**/assets/**',
  filterPattern: sFilterPattern,
  output: sOutput = null,
  format: sFormat = 'html',
} = oProgram;

const iComplexityMax = 10;
const sDirName = 'code-quality-report'; // 输出目录名


const newScan = new oScan();
newScan.init(aArgs, {
  sExt,
  sJscpdExts,
  iJscpdMinLines,
  iJscpdMinTokens,
  iJspcdMaxLines,
  iJspcdMaxSize,
  iThresholdJscpd,
  sIgnorePath,
  sIgnorePattern,
  sFilterPattern,
  sOutput,
  sFormat,
  iComplexityMax,
  sDirName
});
